package com.forum.action;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.forum.dao.UserDAO;
import com.forum.util.BaseAction;
import com.opensymphony.xwork2.Action;

@SuppressWarnings("serial")
@Component("validateNameAction")
@Scope("prototype")
public class ValidateNameAction extends BaseAction{
	private String userName;
	private String tip;
	private UserDAO userDAO;
	private String result;

	public String execute() throws Exception {
		try {
			if(userDAO.validateName(userName)){
				setTip("用户名："+userName+"已存在");
			}
			else{
				setTip("用户名："+userName+"可用");
			}
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e.getMessage());
		}
		JSONObject jo = new JSONObject();
		jo.put("tip", tip);
		result = jo.toString();
		return "success";
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
	
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}
	public UserDAO getUserDAO() {
		return userDAO;
	}
	@Resource
	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}
}
